package com.glls.sbdemo22.controller;

import com.glls.sbdemo22.anno.UnInterception;
import com.glls.sbdemo22.common.BusinessMsgEnum;
import com.glls.sbdemo22.common.R;
import com.glls.sbdemo22.exception.BusinessErrorException;
import com.glls.sbdemo22.pojo.User;
import com.glls.sbdemo22.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @date 2023/5/16
 * @desc
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户模块")
public class UserController {
    @Autowired
    private UserService userService;


    @PostMapping("/login")
    @UnInterception
    public R login(String username, String password){
        System.out.println("登录操作");
        if(username.length()<6){
            throw new BusinessErrorException(BusinessMsgEnum.PARMETER_EXCEPTION);
        }
        return R.ok();
    }



    @GetMapping("/user/{id}")
    @ApiOperation(value = "根据用户唯一标识获取用户信息")
    @ApiImplicitParam(name = "id",value = "用户id",required = true)
    public R user(@PathVariable("id") Long id){

        User user = userService.getById(id);

        return R.ok().data("user",user);
    }



}
